package qsc.algorithm.KMP;

import javax.servlet.ServletContainerInitializer;

/**
 * @auther QiuShangcheng
 * @create 2021/4/16
 */
public class ViolenceMatch {
    public static void main(String[] args) {
        String str1 = "硅硅谷 尚硅谷你尚硅 尚硅谷你尚硅你尚硅谷你好";
        String str2 = "尚硅谷你尚硅你";
        long l1 = System.currentTimeMillis();
        System.out.println("index:" + violenceMatch(str1, str2));
        long l2 = System.currentTimeMillis();
        System.out.println(l2-l1);

    }
    /**
     * 暴力匹配算法
     * @param str1
     * @param str2
     * @return
     */
    public static int violenceMatch(String str1, String str2) {
//        char[] s1Len = str1.toCharArray();
//        char[] s2Len = str2.toCharArray();
        int begin = 0;
        int end = str2.length();
        while (end <= str1.length()-1) {
            String temp = str1.substring(begin, end);
            if (temp.equals(str2)) {
                System.out.println(temp);
                return begin;
            } else {
                begin++;
                end++;
            }
        }
        return -1;
    }
}
